//
//  MineViewController.m
//  Ranging_dev
//
//  Created by Mr.Dynasty on 2019/4/1.
//  Copyright © 2019 Mr.Dynasty. All rights reserved.
//

#import "MineViewController.h"

@interface MineViewController ()
@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self makeView];
}

- (void)makeView {
    
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view).offset(UIEdgeInsetsMake(20, 0, 0, 0));
        make.height.equalTo(50);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = RegularDefaultFont;
    titleLabel.textColor = TextBlackColor;
    titleLabel.text = NSLocalizedString(@"版本号", nil);
    [self.view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view).offset(UIEdgeInsetsMake(20, 15, 0, 0));
        make.height.equalTo(50);
    }];
    
    UILabel *valueLabel = [[UILabel alloc] init];
    valueLabel.font = RegularDefaultFont;
    valueLabel.textColor = TextBlackColor;
    valueLabel.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:valueLabel];
    [valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view).offset(UIEdgeInsetsMake(20, 0, 0, 15));
        make.height.equalTo(50);
    }];
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    // 获取App的版本号
    NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    valueLabel.text = appVersion;
    
    UIButton *logout = [UIButton buttonWithType:UIButtonTypeCustom];
    [logout setBackgroundColor:[UIColor whiteColor]];
    [logout setTitle:NSLocalizedString(@"退出登录", nil) forState:UIControlStateNormal];
    [logout setTitleColor:TextBlackColor forState:UIControlStateNormal];
    logout.titleLabel.font = RegularDefaultFont;
    logout.layer.cornerRadius = 5;
    [logout addTarget:self action:@selector(actionForLogout) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:logout];
    
    [logout mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(valueLabel.mas_bottom).offset(20);
        make.height.equalTo(45);
        make.left.right.equalTo(self.view);
    }];
}

- (void)actionForLogout {
    UserInfoModel *userInfoModel = [[UserInfoModel alloc] init];
    [[UserManager shareManager] saveUserInfoModel:userInfoModel];
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    app.rootTabBar = nil;
    [app changeRootWindow];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
